<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>华鑫农业信息管理系统</title>
<link rel="stylesheet" type="text/css" href="../style/css.css">
  <link href="../css/bootstrap.min.css" rel="stylesheet">
<script language="javascript" type="text/javascript" src="../js/jquery1.4.min.js"></script>
<script language="javascript" type="text/javascript" src="../js/jquery.jslider.js"></script>
  <script src="../js/myScript/app.js"></script>
</head>
<body>
<div class="wrap">

    <jsp:include page="top.jsp"/>

  <div class="main">
    <div class="mainr right">
      <h2><span class="ny_nav">您当前所在的位置：<a href="">首页</a> &gt; 产品展示 &gt; 产品名称</span>产品展示</h2>
      <div class="pad20">
      <h3>产品名称:<span id="produceN"></span></h3>
      <div class="blank10"></div>
        <h1>产品分类：<span id="productClass"></span></h1>
        <h1>营养价值：<span id="productValue"></span></h1>
        <h1>产品功用：<span id="productUse"></span></h1>
        <h1>产品价格：<b id="productPrice"></b><span>(元/斤)</span></h1>
        <div class="pad20">
         <p>产品描述:</p>
          <p class="lead" id="message"></p>
          <button class="btn btn-danger btn-w-md" type="button" id="orderCommit">下单</button>
        </div>

      </div>
    </div>
    <div class="clear"></div>
  </div>
   <jsp:include page="buttom.jsp"/>
</div>
<script type="text/javascript">
  //获取url中？后的参数
  var paramUrl = location.search;
  var ptId = paramUrl.split("=")[1];

//  更具id查询产品
  $.ajax({
    type: "GET",
    url: serverUrl + "/product/queryProductById?PtId=" + ptId,
    xhrFields: {
      withCredentials: true
    },
    dataType: "json",
    success:function (res) {
      if (res.success) {
        $("#produceN").text(res.data.ptName);
        $("#productClass").text(res.data.type.tsName);
        $("#productValue").text(res.data.ptValue);
        $("#productUse").text(res.data.ptUse);
        $("#productPrice").text(res.data.ptPrice);
        $("#message").text(res.data.ptMessage);
      }
    },
    error: function (res) {

    }
  });
  //下单功能
  var user = JSON.parse(sessionStorage.getItem("user"));

  $("#orderCommit").click(function () {
      console.log("sdjfosjofjsoifjosdj");
      $.ajax({
          type: "POST",
          contentType: "application/json;charset=utf-8",
          url: serverUrl + "/order/addOrder",
          xhrFields: {
              withCredentials: true
          },
          data: JSON.stringify({"osStatus": 0, "personId": user.pnId, "productId":ptId}),
          dataType: "json",
          success: function (res) {
              if (res.success) {
                  window.location.href="cpzs.jsp";
              }
          }
      })
  });
</script>
</body>

</html>
